<template>
    <div class="m-footer-menu-bar">
        <dl>
            <dd
                :class="[activeIndex == tab.id ? 'active' : '', 'm-bar-col']"
                v-for="(tab, index) in tabMenus"
                :key="index"
                @click="linkTo(tab)"
            >
               <i :class="['m-bar-icon', tab.icon]"></i>
               <span> {{ tab.label }}</span>

            </dd>
        </dl>
    </div>
</template>

<script>
export default {
  name: 'DuoduocaiH5BottomMenu',

  data() {
    return {
      activeIndex: 0,
    };
  },
  watch: {
    $route: {
      immediate: true,
      handler: function () {
        this.routerName = this.$route.name;
        document.title = this.$route.meta.title;
        if (this.$route.name === 'Expert' || this.$route.name === 'IntelligentRecommendation') {
          this.routerName = 'Master';
        }
        console.log(this.routerName);
        this.activeIndex = (this.tabMenus.find((item) => item.name === this.routerName) || {}).id;
      },
    },
  },
  computed: {
    tabMenus() {
      return [
        {
          label: '首页',
          name: 'Home',
          icon: 'f-home-icon',
          id: 0,
        },
        {
          label: '开奖',
          name: 'Kaijiang',
          icon: 'f-kaijiang-icon',
          id: 1,
        },
        {
          label: '社区',
          name: 'Community',
          icon: 'f-community-icon',
          id: 2,
        },
        {
          label: '我的',
          name: 'My',
          icon: 'f-my-icon',
          id: 3,
        },
      ];
    },
  },
  mounted() {},

  methods: {
    async linkTo({ name, id, handler }) {
      // eslint-disable-next-line eqeqeq
      if (this.activeIndex == id) return;
      if (handler) {
        await handler();
      }
      this.$router.push({
        name: name,
      });
      this.activeIndex = id;
    },
  },
};
</script>

<style scoped lang="scss">
.m-footer-menu-bar {
    position: fixed;
    left: 0;
    bottom: 0;
    z-index: 9;
    width: 100%;
    background: #fff;
    display: flex;
    align-items: center;
    flex-direction: column;
    overflow-x: hidden;
}
dl {
    width: 100%;
    height: 70px;
    display: flex;
    align-items: center;
    .m-bar-col {
        width: 50%;
        flex: 1;
        color: #666;
        font-size: 15px;
        text-align: center;
        line-height: 35px;
        display: flex;
        flex-direction: column;
    }
     .m-bar-icon{
          /* position: relative; */
    width: 26px;
    height:28px;
    display: block;
    margin: 2px auto 0;
     }
}

.m-footer-menu-bar .m-bar-icon.f-home-icon {
    background: url('icons/home.png') no-repeat center center;
    background-size: contain;
}
.m-footer-menu-bar .m-bar-icon.f-kaijiang-icon {
    background: url('icons/kaijiang.png') no-repeat center center;
    background-size: contain;
}
.m-footer-menu-bar .m-bar-icon.f-expert-icon {
    background: url('icons/expert.png') no-repeat center center;
    background-size: contain;
}
.m-footer-menu-bar .m-bar-icon.f-community-icon {
    background: url('icons/community.png') no-repeat center center;
    background-size: contain;
}
.m-footer-menu-bar .m-bar-icon.f-my-icon {
    background: url('icons/my.png') no-repeat center center;
    background-size: contain;
}

.m-footer-menu-bar .m-bar-col.active {
    color: #f84848;
}
.m-footer-menu-bar .m-bar-col.active .m-bar-icon.f-home-icon {
    background: url('icons/home_active.png') no-repeat center center;
    background-size: contain;
}
.m-footer-menu-bar .m-bar-col.active .m-bar-icon.f-kaijiang-icon {
    background: url('icons/kaijiang_active.png') no-repeat center center;
    background-size: contain;
}
.m-footer-menu-bar .m-bar-col.active .m-bar-icon.f-expert-icon {
    background: url('icons/expert_active.png') no-repeat center center;
    background-size: contain;
}
.m-footer-menu-bar .m-bar-col.active .m-bar-icon.f-community-icon {
    background: url('icons/community_active.png') no-repeat center center;
    background-size: contain;
}
.m-footer-menu-bar .m-bar-col.active .m-bar-icon.f-my-icon {
    background: url('icons/my_active.png') no-repeat center center;
    background-size: contain;
}
.m-bar-col.active {
    color: red;
}
</style>
